import { Middleware } from 'koa'

/**
 * 捕获错误的中间件
 */
export default function catchError(): Middleware {
    return async (ctx, next) => {
        try {
            await next()
        } catch (err) {
            console.error(err)
            ctx.status = 500
        }
    }
}
